var app = getApp();
Page({
  data: {
    language: '',
    order_id: "",
    goodList: [],
    totalNum: 0,
    totalPrice: '',
    order_sn: '',
    orderData: null,

    balance: 0,
    payParams: '',
    info_form: {},
    money: '',
    buttons: [],
    pay_sn: '订单编号',
    order_pay_id: '',
    uid: '',
    shareTit: '',
    shareUrl: '',
    shareImg: '',
    shareContent: '',
		styleTwo:'',
    code_url:''
  },

  getOrderDetail: function() {
    var that = this;
    var _url = app.getNetAddresss("order.another-pay-detail");
    _url += "&order_id=" + that.data.order_id;
    app._getNetWork({
      url: _url,
      success: function(response) {
        //var _data = res.data.data;
        if (response.data.result == 1) {
          // 从另外的接口获取
          // var totalPrice = 0;
          // for (var i in response.data.data) {
          //   for (var j in response.data.data[i].has_many_order_goods) {
          //     totalPrice += parseFloat(response.data.data[i].has_many_order_goods[j].price);
          //   }
          // }

          that.setData({
            goodList: response.data.data,
            //	totalPrice: totalPrice.toFixed(2),
          });
        } else {
          wx.showToast({
            title: response.data.msg,
            icon: 'success',
            duration: 2000
          });
          console.log("错误", response.data.msg);
        }
      },
      fail: function(res) {}
    });
  },

  //获取默认分享数据
  getShareInfo: function() {
    var that = this;
    var _url = app.getNetAddresss("member.member.anotherShare");
    _url += "&order_ids=" + that.data.order_id;
    app._getNetWork({
      url: _url,
      success: (response)=> {
        //var _data = res.data.data;
        console.log("ressss::::", response);
        if (response.data.result == 1) {
          that.setData({
            shareTit: response.data.data.title,
            shareUrl: response.data.data.url,
            shareImg: response.data.data.img,
            shareContent: response.data.data.content,
          });
          if(response.data.data.code_url){
            this.setData({
              code_url:response.data.data.code_url
            })
          }
        } else {
          wx.showToast({
            title: response.data.msg,
            icon: 'success',
            duration: 2000
          });
          console.log("错误", response.data.msg);
        }
      },
      fail: function(res) {}
    });

  },
	
  /**
	 * 用户点击右上角分享
	 */
  onShareTimeline: function () {
    var value = wx.getStorageSync('yz_uid');
    var mid = '';
    if (value) {
      mid = value;
    }
    return {
      title: this.data.shareTit,
      desc: this.data.shareContent,
      imageUrl: this.data.shareImg,
      query: 'id=' + this.data.order_id + '&p=' + mid
    };
  },


  // 分享
  onShareAppMessage: function() {
    var value = wx.getStorageSync('yz_uid');
    var path = '';
    if (value) {
      path = value;
    }
    let share_type = 1;
    if(this.data.styleTwo){
      share_type = 2;
    }
    return {
      title: this.data.shareTit,
      desc: this.data.shareContent,
      imageUrl: this.data.shareImg,
      path: '/packageD/buy/payanotherDetail/payanotherDetail?id=' + this.data.order_id + '&p=' +path +'&share_type='+share_type
    };
  },

  //获取实付价格
  getPrice() {
    var value = wx.getStorageSync('yz_uid');
    var path = '';
    if (value) {
      path = value;
    }
    var _url = app.getNetAddresss("order.merge-pay.anotherPayOrder");
    _url += "&order_ids=" + this.data.order_id;
    _url += "&pid=" + path;
    app._getNetWork({
      url: _url,
      success: (response) =>{
        //var _data = res.data.data;
        // console.log("ressss::::", response);
        if (response.data.result == 1) {
          let totalPrice = response.data.data.order_pay.amount;
          this.setData({
            totalPrice
          });
        } else {
          wx.showToast({
            title: response.data.msg,
            icon: 'success',
            duration: 2000
          });
          console.log("错误", response.data.msg);
        }
      },
      fail: function(res) {}
    });
		
  },

  onLoad: function(options) {
    var that = this;
    console.log('options:', options);
    that.setData({
      order_id: options.order_id
    });
    if(options.style){
      this.setData({
        styleTwo:true
      })
    }

    this.getOrderDetail();
    this.getPrice();
    this.getShareInfo();

  },

  onReady: function() {
    let language = wx.getStorageSync('langIndex');
    this.setData({ 'language': language.en});
    // 页面渲染完成
  },
  onShow: function() {
    // 页面显示
  },
  onHide: function() {
    // 页面隐藏
  },
  onUnload: function() {
    // 页面关闭
  }
});
